package lcr;

public class Test0128 {
    public static void main(String[] args) {
        int[] stock = {4,5,8,3,4};
        Solution0128_1 solution0128_1 = new Solution0128_1();
        System.out.println(solution0128_1.stockManagement(stock));
    }
}

class Solution0128_1 {
    public int stockManagement(int[] stock) {
        int length = stock.length;
        if(length == 1) return stock[0];

        int l=0,r = length-1;
        while (l<r){
            int mid = (r + l) >> 1;

            if (stock[mid]<stock[r]){
                r = mid;
            }else if(stock[mid]>stock[r]){
                l = mid+1;
            }else {
                r--;
            }

        }

        return stock[r];
    }
}
